import { defineStore } from 'pinia'
import type { ConversationProps } from '../../type'
import { db } from '../../db'
const useConversationStore = defineStore('conversation', {
  state: () => {
    return {
      conversationList: [] as ConversationProps[],
      selectId: -1 as number
    }
  },
  actions: {
    async getConversationList() {
      this.conversationList = await db.conversations.toArray()
    },
    getConversationById(id: number) {
      return this.conversationList.find(conversation => conversation.id === id)
    },
    setSelectId(id: number) {
      this.selectId = id
    }
  }
})

export default useConversationStore
